package com.example.demo6.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

//http://localhost:8088/hello/test
@Controller //标记的类就是一个SpringMVC Controller 对象
@RequestMapping(value = "/hello") //用来处理请求地址映射的注解
public class HelloController {

    @RequestMapping(value = "/test", method = RequestMethod.GET)
    public void test(){
        System.out.println("this is test method.");
    }

    //请求地址 hello/a
    //@RequestMapping(value = "/a")
    //http://localhost:8088/hello/a
    //请求地址 hello/a/123
    //@RequestMapping(value = "/a/{id}")
    //http://localhost:8088/hello/a
    @RequestMapping(value = "/a/{id}")
    public void test2(@PathVariable String id){
        System.out.println("id = " + id);

    }

    @RequestMapping(value = "/say")
    public String say(Model model){
        model.addAttribute("greet", "Hello Thymeleaf!");
        return "hello/say";
    }
}
